<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>随机算法</title>
  </head>
  <body>
    <script>
      function randomSort(arr) {
        for (let i = 0; i < arr.length; i++) {
          let randomIndex = Math.floor(Math.random() * arr.length);
          let temp = arr[i];
          arr[i] = arr[randomIndex];
          arr[randomIndex] = temp;
        }
        return arr;
      }

      const unsortedArray = [5, 3, 1, 4, 2];
      const sortedArray = randomSort(unsortedArray);
      console.log(`Randomly sorted array: ${sortedArray}`);
    </script>
  </body>
</html>
 